//
//  MeatCartSectionView.m
//  PigMarket
//
//  Created by 张敬 on 2019/7/23.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "MeatCartSectionView.h"

#define selfH 51

@implementation MeatCartSectionView


- (void)setupUI{
    
    self.backgroundColor = mBackgroudColor;
    
    [self addSubview:self.chooseBtn];
    [self addSubview:self.shopNameLab];
}


- (void)setupLayout{
    
    self.height = selfH;

    {
        CGFloat adapterW = 48;
        _chooseBtn.size = CGSizeMake( adapterW, adapterW);
        _chooseBtn.mj_y = 0;
        _chooseBtn.mj_x = 15;
    }
    
    
    {
        _shopNameLab.frame = CGRectMake(59, 0, KScreenWidth -74 , selfH);
    }
    
}


#pragma mark - setter methods

- (void)setShopName:(NSString *)shopName{
    
    _shopName = shopName;
    NSString *newStr = [NSString stringWithFormat:@"%@%@",@" ", shopName];
    NSMutableAttributedString *aims = [newStr createAttributingByIcon:@"meat_cart_shopIcon_black" downIndexImage:@"meat_cart_enter" textColor:UIColorFromRGB(0x333333) font:mMediumFont(17)];
    _shopNameLab.attributedText = aims;
}


- (void)setIsChicked:(BOOL)isChicked{
    
    _isChicked = isChicked;
    NSString *image = isChicked ?@"meat_cart_checked" :@"meat_cart_unchecked";
    [_chooseBtn setImage:[UIImage imageNamed:image] forState:UIControlStateNormal];
}


#pragma mark - getter methods

- (UIButton *)chooseBtn{
    if (!_chooseBtn) {
        _chooseBtn = [UIButton makeButtonWithImageName:@"meat_cart_unchecked"];
        
        kWeakSelf(self);
        _chooseBtn.tapBlock = ^{
            
            if (weakself.dealCartSectionBlock) {
                weakself.dealCartSectionBlock(weakself.chooseBtn);
            }
        };
    }
    return _chooseBtn;
}


- (UILabel *)shopNameLab{
    if (!_shopNameLab) {
        _shopNameLab = [[UILabel alloc] init];
    }
    return _shopNameLab;
}


@end
